package com.fr.dialog.core;

import com.fr.base.Inter;
import com.fr.base.Style;
import com.fr.base.core.BaseCoreConstants;
import com.fr.base.core.ComparatorUtils;
import com.fr.cell.core.GUICoreUtils;
import com.fr.cell.core.layout.LayoutFactory;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;

public class AlignmentPane extends JPanel
{
  private AlignmentComboBox horAlignmentComboBox;
  private AlignmentComboBox verAlignmentComboBox;
  private JComboBox textComboBox;
  private static final String[] TEXT = { Inter.getLocText("StyleAlignment-Wrap_Text"), Inter.getLocText("StyleAlignment-Single_Line"), Inter.getLocText("StyleAlignment-Single_Line(Adjust_Font)"), Inter.getLocText("StyleAlignment-Multi_Line(Adjust_Font)") };
  private JSpinner rotationSpinner;
  private JCheckBox isVerticalTextCheckBox;
  private JRadioButton leftToRightRB;
  private JRadioButton rightToLeftRB;
  private JComboBox imageComboBox;
  private static final String[] IMAGE = { Inter.getLocText("Default"), Inter.getLocText("Image-Extend") };
  private JSpinner leftIndentSpinner;
  private JSpinner rightIndentSpinner;
  private JSpinner spacingBeforeSpinner;
  private JSpinner spacingAfterSpinner;
  private JSpinner lineSpacingSpinner;
  private EventListenerList eventChangeList = new EventListenerList();
  ActionListener actionListener = new ActionListener(???)
  {
    private final AlignmentPane this$0;

    public void actionPerformed()
    {
      this.this$0.fireStateChanged();
    }
  };
  ChangeListener changeListener = new ChangeListener(???)
  {
    private final AlignmentPane this$0;

    public void stateChanged()
    {
      this.this$0.fireStateChanged();
    }
  };

  public AlignmentPane()
  {
    initComponents();
  }

  protected void initComponents()
  {
    setLayout(LayoutFactory.createBorderLayout());
    setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    JPanel localJPanel1 = new JPanel();
    add(localJPanel1, "North");
    localJPanel1.setLayout(new BoxLayout(localJPanel1, 1));
    JPanel localJPanel2 = new JPanel(new GridLayout(1, 2, 2, 4));
    localJPanel1.add(localJPanel2);
    JPanel localJPanel3 = new JPanel(new GridLayout(1, 1));
    localJPanel2.add(localJPanel3);
    localJPanel3.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("StyleAlignment-Horizontal")));
    this.horAlignmentComboBox = new AlignmentComboBox(BaseCoreConstants.HorizontalAlignmentArray);
    this.horAlignmentComboBox.addActionListener(this.actionListener);
    localJPanel3.add(this.horAlignmentComboBox);
    JPanel localJPanel4 = new JPanel(new GridLayout(1, 1));
    localJPanel2.add(localJPanel4);
    localJPanel4.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("StyleAlignment-Vertical")));
    this.verAlignmentComboBox = new AlignmentComboBox(BaseCoreConstants.VerticalAlignmentArray);
    this.verAlignmentComboBox.addActionListener(this.actionListener);
    localJPanel4.add(this.verAlignmentComboBox);
    JPanel localJPanel5 = new JPanel(new GridLayout(1, 2, 2, 4));
    localJPanel1.add(localJPanel5);
    JPanel localJPanel6 = new JPanel();
    localJPanel5.add(localJPanel6);
    localJPanel6.setLayout(new GridLayout(1, 1));
    localJPanel6.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("StyleAlignment-Text_Style") + ":"));
    this.textComboBox = new JComboBox(TEXT);
    this.textComboBox.addActionListener(this.actionListener);
    localJPanel6.add(this.textComboBox);
    JPanel localJPanel7 = new JPanel();
    localJPanel5.add(localJPanel7);
    localJPanel7.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("Image-Image_Layout")));
    localJPanel7.setLayout(new GridLayout(1, 1));
    this.imageComboBox = new JComboBox(IMAGE);
    this.imageComboBox.addActionListener(this.actionListener);
    localJPanel7.add(this.imageComboBox);
    JPanel localJPanel8 = new JPanel();
    localJPanel1.add(localJPanel8);
    localJPanel8.setLayout(new BoxLayout(localJPanel8, 1));
    localJPanel8.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("StyleAlignment-Text_Rotation") + ":"));
    JPanel localJPanel9 = new JPanel();
    localJPanel8.add(localJPanel9);
    localJPanel9.setLayout(new FlowLayout(0, 1, 0));
    JPanel localJPanel10 = new JPanel();
    localJPanel9.add(localJPanel10);
    this.isVerticalTextCheckBox = new JCheckBox(Inter.getLocText("StyleAlignment-Vertical_Text"), false);
    this.isVerticalTextCheckBox.addActionListener(this.actionListener);
    localJPanel10.add(this.isVerticalTextCheckBox);
    this.isVerticalTextCheckBox.addActionListener(new ActionListener(this)
    {
      private final AlignmentPane this$0;

      public void actionPerformed()
      {
        if (AlignmentPane.access$000(this.this$0).isSelected())
        {
          AlignmentPane.access$100(this.this$0).setEnabled(false);
          AlignmentPane.access$200(this.this$0).setEnabled(true);
          AlignmentPane.access$300(this.this$0).setEnabled(true);
        }
        else
        {
          AlignmentPane.access$100(this.this$0).setEnabled(true);
          AlignmentPane.access$200(this.this$0).setEnabled(false);
          AlignmentPane.access$300(this.this$0).setEnabled(false);
        }
      }
    });
    this.leftToRightRB = new JRadioButton(Inter.getLocText("StyleAlignment-Left_To_Right"));
    this.leftToRightRB.addActionListener(this.actionListener);
    localJPanel10.add(this.leftToRightRB);
    this.rightToLeftRB = new JRadioButton(Inter.getLocText("StyleAlignment-Right_To_Left"));
    this.rightToLeftRB.addActionListener(this.actionListener);
    localJPanel10.add(this.rightToLeftRB);
    ButtonGroup localButtonGroup = new ButtonGroup();
    localButtonGroup.add(this.leftToRightRB);
    localButtonGroup.add(this.rightToLeftRB);
    this.rightToLeftRB.setSelected(true);
    JPanel localJPanel11 = new JPanel();
    localJPanel8.add(localJPanel11);
    localJPanel11.setLayout(new FlowLayout(0, 1, 0));
    localJPanel11.add(new JLabel(" " + Inter.getLocText("StyleAlignment-Text_Rotation") + ":"));
    this.rotationSpinner = new JSpinner(new SpinnerNumberModel(0, -90, 90, 1));
    this.rotationSpinner.addChangeListener(this.changeListener);
    GUICoreUtils.setColumnForSpinner(this.rotationSpinner, 3);
    localJPanel11.add(this.rotationSpinner);
    localJPanel11.add(new JLabel(Inter.getLocText("StyleAlignment-Degrees")));
    localJPanel11.add(new JLabel("(" + Inter.getLocText("StyleAlignment-between_-90_and_90") + ")"));
    JPanel localJPanel12 = new JPanel();
    localJPanel1.add(localJPanel12);
    localJPanel12.setLayout(new GridLayout(1, 2));
    localJPanel12.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("Sytle-Indentation") + ":"));
    this.leftIndentSpinner = new JSpinner(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
    this.leftIndentSpinner.addChangeListener(this.changeListener);
    GUICoreUtils.setColumnForSpinner(this.leftIndentSpinner, 3);
    localJPanel12.add(createCenterFlowPane(Inter.getLocText("Style-Left_Indent") + "(" + Inter.getLocText("px") + ")", this.leftIndentSpinner));
    this.rightIndentSpinner = new JSpinner(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
    this.rightIndentSpinner.addChangeListener(this.changeListener);
    GUICoreUtils.setColumnForSpinner(this.rightIndentSpinner, 3);
    localJPanel12.add(createCenterFlowPane(Inter.getLocText("Style-Right_Indent") + "(" + Inter.getLocText("px") + ")", this.rightIndentSpinner));
    JPanel localJPanel13 = new JPanel();
    localJPanel1.add(localJPanel13);
    localJPanel13.setLayout(new GridLayout(1, 3));
    localJPanel13.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("Style-Spacing") + ":"));
    this.spacingBeforeSpinner = new JSpinner(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
    this.spacingBeforeSpinner.addChangeListener(this.changeListener);
    GUICoreUtils.setColumnForSpinner(this.spacingBeforeSpinner, 3);
    localJPanel13.add(createCenterFlowPane(Inter.getLocText("Style-Spacing_Before"), this.spacingBeforeSpinner));
    this.spacingAfterSpinner = new JSpinner(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
    this.spacingAfterSpinner.addChangeListener(this.changeListener);
    GUICoreUtils.setColumnForSpinner(this.spacingAfterSpinner, 3);
    localJPanel13.add(createCenterFlowPane(Inter.getLocText("Style-Spacing_After"), this.spacingAfterSpinner));
    this.lineSpacingSpinner = new JSpinner(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
    this.lineSpacingSpinner.addChangeListener(this.changeListener);
    GUICoreUtils.setColumnForSpinner(this.lineSpacingSpinner, 3);
    localJPanel13.add(createCenterFlowPane(Inter.getLocText("Style-Line_Spacing"), this.lineSpacingSpinner));
  }

  public void addChangeListener(ChangeListener paramChangeListener)
  {
    this.eventChangeList.add(ChangeListener.class, paramChangeListener);
  }

  public void fireStateChanged()
  {
    Object[] arrayOfObject = this.eventChangeList.getListenerList();
    ChangeEvent localChangeEvent = null;
    for (int i = arrayOfObject.length - 2; i >= 0; i -= 2)
      if (arrayOfObject[i] == ChangeListener.class)
      {
        if (localChangeEvent == null)
          localChangeEvent = new ChangeEvent(this);
        ((ChangeListener)arrayOfObject[(i + 1)]).stateChanged(localChangeEvent);
      }
  }

  private JPanel createCenterFlowPane(String paramString, JComponent paramJComponent)
  {
    JPanel localJPanel = new JPanel();
    localJPanel.setLayout(new FlowLayout(1));
    localJPanel.add(new JLabel(paramString));
    localJPanel.add(paramJComponent);
    return localJPanel;
  }

  public void populate(Style paramStyle)
  {
    this.horAlignmentComboBox.setSelectedAlignment(paramStyle.getHorizontalAlignment());
    this.verAlignmentComboBox.setSelectedAlignment(paramStyle.getVerticalAlignment());
    if (paramStyle.getTextStyle() == 1)
      this.textComboBox.setSelectedIndex(1);
    else if (paramStyle.getTextStyle() == 2)
      this.textComboBox.setSelectedIndex(2);
    else if (paramStyle.getTextStyle() == 3)
      this.textComboBox.setSelectedIndex(3);
    else
      this.textComboBox.setSelectedIndex(0);
    int i = paramStyle.getImageLayout();
    if (i == 2)
      this.imageComboBox.setSelectedIndex(1);
    else
      this.imageComboBox.setSelectedIndex(0);
    if (paramStyle.getVerticalText() == 1)
    {
      this.isVerticalTextCheckBox.setSelected(true);
      this.rotationSpinner.setEnabled(false);
      if (paramStyle.getTextDirection() == 1)
      {
        this.leftToRightRB.setEnabled(true);
        this.rightToLeftRB.setEnabled(true);
        this.leftToRightRB.setSelected(true);
        this.rightToLeftRB.setSelected(false);
      }
      else
      {
        this.leftToRightRB.setEnabled(true);
        this.rightToLeftRB.setEnabled(true);
        this.leftToRightRB.setSelected(false);
        this.rightToLeftRB.setSelected(true);
      }
    }
    else
    {
      this.isVerticalTextCheckBox.setSelected(false);
      this.leftToRightRB.setEnabled(false);
      this.rightToLeftRB.setEnabled(false);
      this.rotationSpinner.setEnabled(true);
      this.rotationSpinner.setValue(new Integer(paramStyle.getRotation()));
    }
    this.leftIndentSpinner.setValue(new Integer(paramStyle.getPaddingLeft()));
    this.rightIndentSpinner.setValue(new Integer(paramStyle.getPaddingRight()));
    this.spacingBeforeSpinner.setValue(new Integer(paramStyle.getSpacingBefore()));
    this.spacingAfterSpinner.setValue(new Integer(paramStyle.getSpacingAfter()));
    this.lineSpacingSpinner.setValue(new Integer(paramStyle.getLineSpacing()));
  }

  public void checkValid()
    throws Exception
  {
    int i = ((Integer)this.rotationSpinner.getValue()).intValue();
    if ((i > 90) || (i < -90))
      throw new Exception(Inter.getLocText("StyleAlignment-The_value_of_rotation_must_between_-90_and_90_degrees") + ".");
  }

  public Style update(Style paramStyle)
  {
    if (paramStyle == null)
      return paramStyle;
    paramStyle = paramStyle.deriveHorizontalAlignment(this.horAlignmentComboBox.getSelectedAlignment());
    paramStyle = paramStyle.deriveVerticalAlignment(this.verAlignmentComboBox.getSelectedAlignment());
    if (ComparatorUtils.equals(this.textComboBox.getSelectedItem(), TEXT[0]))
      paramStyle = paramStyle.deriveTextStyle(0);
    else if (ComparatorUtils.equals(this.textComboBox.getSelectedItem(), TEXT[1]))
      paramStyle = paramStyle.deriveTextStyle(1);
    else if (ComparatorUtils.equals(this.textComboBox.getSelectedItem(), TEXT[2]))
      paramStyle = paramStyle.deriveTextStyle(2);
    else
      paramStyle = paramStyle.deriveTextStyle(3);
    if (ComparatorUtils.equals(this.imageComboBox.getSelectedItem(), IMAGE[0]))
      paramStyle = paramStyle.deriveImageLayout(3);
    else if (ComparatorUtils.equals(this.imageComboBox.getSelectedItem(), IMAGE[1]))
      paramStyle = paramStyle.deriveImageLayout(2);
    if (this.isVerticalTextCheckBox.isSelected())
    {
      paramStyle = paramStyle.deriveVerticalText(1);
      paramStyle = paramStyle.deriveRotation(0);
      if (this.leftToRightRB.isSelected())
        paramStyle = paramStyle.deriveTextDirection(1);
      else
        paramStyle = paramStyle.deriveTextDirection(0);
    }
    else
    {
      paramStyle = paramStyle.deriveVerticalText(0);
      paramStyle = paramStyle.deriveRotation(((Integer)this.rotationSpinner.getValue()).intValue());
    }
    paramStyle = paramStyle.derivePaddingLeft(((Integer)this.leftIndentSpinner.getValue()).intValue());
    paramStyle = paramStyle.derivePaddingRight(((Integer)this.rightIndentSpinner.getValue()).intValue());
    paramStyle = paramStyle.deriveSpacingBefore(((Integer)this.spacingBeforeSpinner.getValue()).intValue());
    paramStyle = paramStyle.deriveSpacingAfter(((Integer)this.spacingAfterSpinner.getValue()).intValue());
    paramStyle = paramStyle.deriveLineSpacing(((Integer)this.lineSpacingSpinner.getValue()).intValue());
    return paramStyle;
  }

  static JCheckBox access$000(AlignmentPane paramAlignmentPane)
  {
    return paramAlignmentPane.isVerticalTextCheckBox;
  }

  static JSpinner access$100(AlignmentPane paramAlignmentPane)
  {
    return paramAlignmentPane.rotationSpinner;
  }

  static JRadioButton access$200(AlignmentPane paramAlignmentPane)
  {
    return paramAlignmentPane.leftToRightRB;
  }

  static JRadioButton access$300(AlignmentPane paramAlignmentPane)
  {
    return paramAlignmentPane.rightToLeftRB;
  }
}